<?php


function alr_() {/*{{{*/

}/*}}}*/
function cki_() {/*{{{*/

}/*}}}*/
function cst_arr($a, $array_key='name') {/*{{{*/
    if (!is_array($a)) {
        $tmp_a = $a;
        $a = array();
        $a["$array_key"] = $tmp_a;
    }
    return $a;
}/*}}}*/
function cst_def($arg, $default='') {/*{{{*/
    if (isset($arg) && $arg) {
        $default = $arg;
    }
    return $default;
}/*}}}*/
function cst_lbl($a=array()) {/*{{{*/
    $name = $a['name'];
    $label = $a['label'];
    if (!$label) {
        $label = $name;
        $label = preg_replace('/_/', ' ', $label);
        $label = ucwords($label);
    }
    return $label;
}/*}}}*/
function dat_() {/*{{{*/

}/*}}}*/
function dba_col($a) {/*{{{*/
    $table = $a;
    $sql = "show columns from `$table`";
    $result = mysql_query($sql);
    $column = array();
    while ($col = mysql_fetch_assoc($result)) {
        $column[] = $col;
    }
    return $column;
}/*}}}*/
function dba_sel($a) {/*{{{*/
    $a = cst_arr($a, 'sql');
    $sql = $a['sql'];
    $result = mysql_query($sql);

    $field = array();
    $field_count = mysql_num_fields($result);
    for ($i=0; $i<$field_count; $i++) {
        $field_tmp['type']  = mysql_field_type($result, $i);
        $field_tmp['name']  = mysql_field_name($result, $i);
        $field_tmp['len']   = mysql_field_len($result, $i);
        $field_tmp['flags'] = mysql_field_flags($result, $i);
        $field[] = $field_tmp;
        unset($field_tmp);
    }
    $r['field'] = $field;

    $data = array();
    while ($row = mysql_fetch_assoc($result)) {
        $data[] = $row;
    }
    $r['data'] = $data;
    return $r;
}/*}}}*/
function dba_ais($a) { }
function dba_aii($a) { }
function dba_aiu($a) { }
function dba_aid($a) { }
function dba_sis($a) {/*{{{*/
    $a = cst_arr($a);
    $table = $a['name'];
    $col_info = dba_col($table);
    foreach ($col_info as $c) {
        $col_name = $c['Field'];
        $col_type = $c['Type'];
        if ($col_name == 'id') { continue; }
        $col_value = dba_san(array(
            'value' =>  $_POST[$col_name],
            'type'  =>  $col_type,
            ));
        if (get_magic_quotes_gpc()) { $col_value = stripslashes($col_value); }
        $col_value = mysql_real_escape_string($col_value);
        $scol_names  .= "`$col_name`, ";
        $scol_values .= "'$col_value', ";
    }
    $scol_names  = preg_replace('/,\s$/', '', $scol_names);
    $scol_values = preg_replace('/,\s$/', '', $scol_values);
    $sql = "insert into `$table` ($scol_names) values ($scol_values)";
    mysql_query($sql);
    $last_insert_id = mysql_insert_id();
    return $last_insert_id;
}/*}}}*/
function dba_sif($a) {/*{{{*/
    $table = $a;
    $col_info = dba_col($table);
    foreach ($col_info as $c) {
        $col_name = $c['Field'];
        if ($col_name == 'id') { continue; }
        if ($col_name == 'data') {
            $col_value = file_get_contents($_FILES[$table]['tmp_name']);
        } elseif ($_FILES[$table][$col_name]) {
            $col_value = $_FILES[$table][$col_name];
        } elseif ($_POST[$col_name]) {
            $col_value = $_POST[$col_name];
        }
        if (get_magic_quotes_gpc()) { $col_value = stripslashes($col_value); }
        $col_value = mysql_real_escape_string($col_value);
        $scol_names  .= "`$col_name`, ";
        $scol_values .= "'$col_value', ";
    }
    $scol_names  = preg_replace('/,\s$/', '', $scol_names);
    $scol_values = preg_replace('/,\s$/', '', $scol_values);
    $sql = "insert into `$table` ($scol_names) values ($scol_values)";
    mysql_query($sql);
    $last_insert_id = mysql_insert_id();
    return $last_insert_id;
}/*}}}*/
function dba_san($a) {/*{{{*/
    $value = $a['value'];
    $type  = $a['type'];

    if (is_array($value)) {
        $value = implode(",", $value);
        return $value;
    }

    if (!$value && $type=='date') {
        $value = '0000-00-00';
        return $value;
    }

    return $value;
}/*}}}*/
function dbg_() {/*{{{*/

}/*}}}*/
function dir_ls($a=array()) {/*{{{*/

	$excludes=array();
	if (isset($a['excludes']) && $a['excludes']) { $excludes = $a['excludes']; }
	$excludes_exact = array();
	$excludes_fuzzy = array();
	for ($i=0; $i <= count($excludes); $i++) {
		if(preg_match("/\*/", $excludes[$i])) {
			$excludes_fuzzy[]=$excludes[$i];
		} else {
			$excludes_exact[]=$excludes[$i];
		}
	}
	$dir='';
	if(isset($a['dir']) && $a['dir']) { $dir=$a['dir']; }
	$oa_dir_ls=array();
	$d = dir($dir);
	while(false !== ($entry=$d->read())) {
		if(in_array($entry, $excludes_exact)) { continue; }
		foreach($excludes_fuzzy as $value) {
			$value=preg_replace("/\*/", ".*", $value);
			$value=preg_replace("/\./", "\.", $value);
			if(preg_match("/$value/", $entry)) { continue 2; }
		}
		$oa_dir_ls[]=$entry;
	}
	$d->close();
	return $oa_dir_ls;
}/*}}}*/
function doc_() {/*{{{*/

}/*}}}*/
function frm_dsp($a=array()) {/*{{{*/
 
	$name   = ''; if (isset($a['name']) && $a['name']) { $name = $a['name']; }

    $method = 'post'; 
    if (isset($a['method']) && $a['method']) { $method = $a['method']; }

    $action = ''; if (isset($a['action']) && $a['action']) { $action = $a['action']; }

    $process = $name.'_process'; 
    if (isset($a['process']) && $a['process']) { $process = $a['process']; }

    $thank = $name.'_thank'; 
    if (isset($a['thank']) && $a['thank']) { $thank = $a['thank']; }

	$layout = $a['layout'];

    $e_output = array();

    foreach ($a['elements'] as $e) {
        $e_output[] = $e['output'];
        $e_bvalid[] = $e['bvalid'];
    }

    if (POST_SELF && !in_array(false, $e_bvalid)) {
        if (function_exists("$process") && $_SESSION['va'][$name]['display']==true) {
            $_SESSION['va'][$name]['process'] = true;
            $output = $process();
        } 
        if (function_exists("$thank") && $_SESSION['va'][$name]['process']==true) {
            $output = $thank();
            unset($_SESSION['va'][$name]);
        } else {
            header("Location: $_SERVER[HTTP_REFERER]");
        }
    } else {
        $_SESSION['va'][$name]['display'] = true;
        $output  = "\n<form name=\"$name\" enctype=\"multipart/form-data\" method=\"$method\" action=\"$action\" id=\"$name\">";
        $output .= lyt_rc(array(
            'name'	    =>	$name,
            'data'	    =>	$e_output,
            'rc_type'	=>	$layout['rc_type'],
            'rc_nos'	=>	$layout['rc_nos'],
            'flow'		=>	$layout['flow'],
        ));
        $output .= "</form>\n";
    }
    return $output;
}/*}}}*/
function frm_val($a=array()) {/*{{{*/
    $name    = $a['name'];
    $default = $a['default'];
    if ($_POST) {
        return $_POST["$name"];
    } elseif ($default) {
        return $default;
    } else {
        return '';
    }
}/*}}}*/
function frm_vaf($a=array()) {/*{{{*/
}/*}}}*/
function frm_vad($a) {/*{{{*/
    $fn_valid = $a['fn_valid'];
    $fn_emsg  = $a['fn_emsg'];
    $value = $a['value'];
    $valid = true;
    if (POST_SELF && function_exists($fn_valid)) {
        $valid = $fn_valid($value);
    }
    if ($valid == true) {
        $msg = '';
    } else {
        $msg = $fn_emsg;
    }
    $r['bvalid'] = $valid;
    $r['emsg'] = $msg; 
    return $r;
}/*}}}*/
function frm_txt($a) {/*{{{*/
    $a = cst_arr($a);
	$name  = $a['name'];
    $label = cst_lbl(array(
        'name'  =>  $name,
        'label' =>  $a['label'],
        ));
	$help  = $a['help'];
    $default = $a['default'];

    $size = 40;
    if (isset($a['size']) && $a['size']) { $size = $a['size']; }

    $value = frm_val(array(
        'name'      =>  $name,
        'default'   =>  $default,
    ));

    $vresult = frm_vad(array(
        'fn_valid'  =>  $a['fvalid']['name'],
        'fn_emsg'   =>  $a['fvalid']['emsg'],
        'value'     =>  $value,
        ));
    $r['bvalid'] = $vresult['bvalid'];

    $output = frm_out(array(
        'name'  =>  $name,
        'label' =>  $label,
        'ctrl'  =>  "<input type=\"text\" name=\"$name\" id=\"$name\" size=\"$size\" value=\"$value\" />",
        'msg'   =>  $vresult['emsg'],
        'help'  =>  $help,
    ));
    $r['output'] = $output;

    return $r;
}/*}}}*/
function frm_txd($a=array()) {/*{{{*/
    $name  = $a['name'];
    $label = $a['label'];
    $help  = $a['help'];
    $default = $a['default'];

    $size = 15;
    if (isset($a['size']) && $a['size']) { $size = $a['size']; }

    $value = frm_val(array(
        'name'  =>  $name,
        'default'   =>  $default,
        ));

    $jas_cal_trg = jas_cal_trg(array( 'name'  =>  $name,));

    $r['bvalid'] = true;

    $r['output'] = frm_out(array(
        'name'  =>  "cnr_$name",
        'label' =>  $label,
        'ctrl'  =>  "<input type=\"text\" name=\"$name\" id=\"$name\" size=\"$size\" value=\"$value\" $jas_cal_trg />",
        'msg'   =>  $msg,
        'help'  =>  $help,
    ));

    return $r;
}/*}}}*/
function frm_txa($a) {/*{{{*/
    $a = cst_arr($a);
	$name  = $a['name'];
    $label = cst_lbl(array(
        'name'  =>  $name,
        'label' =>  $a['label'],
        ));
	$help = $a['help'];
    $rows = 5;
	if (isset($a['rows']) && $a['rows']) { $rows = $a['rows']; }
    $cols = 40;
	if (isset($a['cols']) && $a['cols']) { $cols = $a['cols']; }

    $default = $a['default'];

    $value = frm_val(array(
        'name'      =>  $name,
        'default'   =>  $default,
        ));

    $vresult = frm_vad(array(
        'fn_valid'  =>  $a['fvalid']['name'],
        'fn_emsg'   =>  $a['fvalid']['emsg'],
        'value'     =>  $value,
        ));
    $r['bvalid'] = $vresult['bvalid'];

    $r['output'] = frm_out(array(
        'name'  =>  $name,
        'label' =>  $label,
        'ctrl'  =>  "<textarea name=\"$name\" id=\"$name\" rows=\"$rows\" cols=\"$cols\">$value</textarea>",
        'msg'   =>  $vresult['emsg'],
        'help'  =>  $help,
    ));

    return $r;
}/*}}}*/
function frm_sel($a=array()) {/*{{{*/
 	$name = $a['name'];
    $label = cst_lbl(array(
        'name'  =>  $name,
        'label' =>  $a['label'],
        ));
	$help = $a['help'];
    $default = $a['default'];

    $size = 1;
    if (isset($a['size']) && $a['size']) { $size = $a['size']; }

    $multiple = '';
    if (isset($a['multiple']) && $a['multiple']) { $multiple = 'multiple'; }

    $lvp_sel = $a['lvp_sel'];
    $select_opts = "";
    $values = frm_val(array(
        'name'      =>  $name,
        'default'   =>  $default,
        ));
    if ($values=='') { $values = array(); }
    foreach ($lvp_sel as $k_sel_label => $v_sel_value) {
        $selected = '';
        if (in_array($v_sel_value, $values)) { $selected = 'selected'; }
        $select_opts .= "<option value=\"$v_sel_value\" $selected >$k_sel_label</option>\n";
    }

    $r['bvalid'] = true;

    $r['output'] = frm_out(array(
        'name'  =>  $name,
        'label' =>  $label,
        'ctrl'  =>  "<select name=\"{$name}[]\" id=\"$name\" size=\"$size\" $multiple >\n $select_opts </select>\n",
        'msg'   =>  $msg,
        'help'  =>  $help,
    ));

    return $r;
}/*}}}*/
function frm_cbx($a=array()) {/*{{{*/
 	$name    = $a['name'];
	$label   = $a['label'];
	$help    = $a['help'];
    $layout  = $a['layout'];
    $default = $a['default'];
    $lvp_cbx = $a['lvp_cbx'];
    $checkbox_ctrls = array();
    $values = frm_val(array(
        'name'      =>  $name,
        'default'   =>  $default,
        ));
    if ($values=='') { $values = array(); }
    foreach ($lvp_cbx as $k_cbx_label => $v_cbx_value) {
        $checked = '';
        if (in_array($v_cbx_value, $values)) { $checked = 'checked'; }
        $checkbox_ctrls[] = "<input type=\"checkbox\" name=\"{$name}[]\" value=\"$v_cbx_value\" $checked /> $k_cbx_label";
    }
    $checkbox_ctrls = lyt_rc(array(
           'name'    => $layout['name'],
           'data'    => $checkbox_ctrls,
           'rc_type' => 'cols',
           'rc_nos'  => $layout['rc_nos'],
           'flow'    => $layout['flow'],
        ));

    $r['bvalid'] = true;

    $r['output'] = frm_out(array(
        'name'  =>  $name,
        'label' =>  $label,
        'ctrl'  =>  "$checkbox_ctrls",
        'msg'   =>  $msg,
        'help'  =>  $help,
        ));

    return $r;
}/*}}}*/
function frm_fie($a=array()) {/*{{{*/
    $a = cst_arr($a);
    $name  = $a['name'];
    $label = cst_lbl(array('name'=> $name, 'label' => $a['label']));
	$help = $a['help'];

    $r['bvalid'] = true;

    $r['output'] = frm_out(array(
        'name'  =>  $name,
        'label' =>  $label,
        'ctrl'  =>  "<input type=\"file\" name=\"$name\" />",
        'msg'   =>  $msg,
        'help'  =>  $help,
    ));

    return $r;
}/*}}}*/
function frm_lbl($a) {/*{{{*/
    $name  = $a['name'];
    $label = $a['label'];
    $r['bvalid'] = true;
    $r['output'] = "<div id=\"$name\">$label</div>";
    return $r;
}/*}}}*/
function frm_btn() {/*{{{*/
}/*}}}*/
function frm_btr() {/*{{{*/
}/*}}}*/
function frm_bts($a=array()) {/*{{{*/
    $a = cst_arr($a);
    $name   = $a['name'];
    $label  = cst_lbl(array('name'=>$name, 'label'=>$a['label']));

    $vresult = frm_vad(array(
        'fn_valid'  =>  $a['fvalid']['name'],
        'fn_emsg'   =>  $a['fvalid']['emsg'],
        'value'     =>  $value,
        ));
    $r['bvalid'] = $vresult['bvalid'];

    $output = frm_out(array(
        'name'  =>  $name, 
        'label' =>  '&nbsp;', 
        'ctrl'  =>  "<input type=\"submit\" name=\"$name\" value=\"$label\" />",
        'msg'   =>  '&nbsp;',
        'help'  =>  '&nbsp;',
    ));
    $r['output'] = $output;

    return $r;
}/*}}}*/
function frm_out($a) {/*{{{*/
    $o = '';
    $name  = $a['name'];
    $label = $a['label'];
    $ctrl  = $a['ctrl'];
    $msg   = $a['msg'];
    $help  = $a['help'];

    $o  = "\n<div id=\"$name\">\n";
    $o .= "<div id=\"flabel\">$label</div>\n";
    $o .= "<div id=\"fctrl\">$ctrl</div>\n";
    $o .= "<div id=\"fhelp\">$help</div>\n";
    $o .= "<div id=\"femsg\">$msg</div>\n";
    $o .= "</div>\n";

    return $o;
}/*}}}*/
function frm_ais($a) { }
function frm_sis($a) { }
function jas_jos_adm() {/*{{{*/
    
}/*}}}*/
function jas_cal_trg($a=array()) {/*{{{*/
    $name = $a['name'];
    $jas_cal_trg = "";
    if (APP_NAM == 'jos') {
        $jas_cal_trg = "onclick=\"return showCalendar('$name', '%Y-%m-%d');\"";
    }
    return $jas_cal_trg;
}/*}}}*/
function kfe_() {/*{{{*/
    $o_txt  = 'Sing a song of sixpence,';
    $o_txt .= 'A pocket full of rye.';
    $o_txt .= 'Four and twenty blackbirds,';
    $o_txt .= 'Baked in a pie.';
    return $o_txt;
}/*}}}*/
function lng_mrk($a) {/*{{{*/

    $out = preg_replace('/\?\s(.*)/', '<a title="\1">[?]</a>', $a);

    return $out;
}/*}}}*/
function lvp_tbl($a) {/*{{{*/
    $table = $a['table'];
    $col_label = $a['label'];
    $col_value = $a['value'];

    $sql = "select * from `$table` order by `$col_label`";
    $result = mysql_query($sql);
    $lvp = array();
    while ($row = mysql_fetch_assoc($result)) {
        $lvp[$row[$col_label]] = $row[$col_value];
    }
    return $lvp;
}/*}}}*/
function lvp_nar($a) {/*{{{*/
    $col_lv = $a;

    $lvp = array();
    foreach ($col_lv as $lv) {
        $lvp[$lv] = $lv;
    }
    return $lvp;
}/*}}}*/
function lyt_rc($a=array()) {/*{{{*/
	$name = $a['name'];
	$data = $a['data'];

	$rc_type = 'cols';
	if (isset($a['rc_type']) && $a['rc_type']) { $rc_type = $a['rc_type']; }

    $rc_nos = 1;
	if (isset($a['rc_nos']) && $a['rc_nos']) { $rc_nos = $a['rc_nos']; }

	$flow = 'accross';
	if (isset($a['flow']) && $a['flow']) { $flow = $a['flow']; }

	$data_nos = count($data);
	if ($rc_type=='cols') {
		$cols = $rc_nos;
		$rows = ceil($data_nos/$cols);
	} else {
		$rows = $rc_nos;
		$cols = ceil($data_nos/$rows);
	}
	$o_trtd = '';
	if ($flow=='accross') {
		for($r=1; $r<=$rows; $r++) {
			$o_trtd .= "<tr>\n";
			for($c=1; $c<=$cols; $c++) {
				$o_trtd .= "<td>";
				$o_trtd .= array_shift($data);
				$o_trtd .= "</td>\n";
			}
			$o_trtd .= "</tr>\n";
		}
	} else {
		$o_trtd .= "<tr>\n";
		for($c=1; $c<=$cols; $c++) {
			$o_trtd .= "<td valign=\"top\">\n";
			$o_trtd .= "<table id=\"inner\">\n";
			for($r=1; $r<=$rows; $r++) {
				$o_trtd .= "<tr>";
				$o_trtd .= "<td>";
				$o_trtd .= array_shift($data);
				$o_trtd .= "</td>";
				$o_trtd .= "</tr>\n";
			}
			$o_trtd .= "</table>\n";
			$o_trtd .= "</td>\n";
		}
		$o_trtd .= "</tr>\n";
	}
	$o_html  = ''."\n";
	$o_html .= "<table id=\"$name\">\n";
	$o_html .= $o_trtd;
	$o_html .= "</table>\n";
	return $o_html;
}/*}}}*/
function cvr_() {/*{{{*/
}/*}}}*/
function pge_adm_tle($a) { /*{{{*/
    $title = cst_def($a['title'], MOD_NAM);
    $subtitle   =   $a['subtitle'];
    $image = cst_def($a['image'], 'generic.png');

    switch (APP_NAM) {
        case 'jos':
            if ($image != 'generic.png') {
                $class_name = substr($image, 0, -4);
                $style .= ".icon-48-$class_name { background-image: url(".MOD_ADM_URI_REP."/images/$image); }";
                $doc =& JFactory::getDocument();
                $doc->addStyleDeclaration($style);
            }
            JToolBarHelper::title(JText::_($title)." <small><small>$subtitle</small></small>", $image );
            return;
            break;
    }
    return $out;
}/*}}}*/
function pge_adm_tbr($a) {
    $form  = cst_def($a['form']);
    $button = array(
        'add'   =>  '',
        'edit'  =>  '',
        'remove'=>  '',
        'save'  =>  '',
        'apply' =>  '',
        'cancel'=>  '',
        );
    $button = array_merge($button, $a['button']);
    $option = $_GET['option'];

    switch (APP_NAM) {
        case 'jos':
            if ($button['add'])    { JToolBarHelper::addNewX(); }
            if ($button['edit'])   { JToolBarHelper::editListX(); }
            if ($button['remove']) { JToolBarHelper::deleteList(); }
            if ($button['save'])   { JToolBarHelper::save(); }
            if ($button['apply'])  { JToolBarHelper::apply(); }
            if ($button['cancel']) { JToolBarHelper::cancel(); }
            echo <<<EOT
\n<script language="javascript">
function submitbutton(task) {
    if (task=='add')    { 
        document.forms['$form'].action = 'index.php?option=$option&d=$button[add]'; 
        document.forms['$form'].submit(); 
    }
    if (task=='edit')   { 
        document.forms['$form'].action = 'index.php?option=$option&d=$button[edit]'; 
        document.forms['$form'].submit(); 
    }
    if (task=='remove') { 
        document.forms['$form'].action = 'index.php?option=$option&d=$button[remove]'; 
        document.forms['$form'].submit(); 
    }
    if (task=='save')   { 
        document.forms['$form'].action = 'index.php?option=$option&d=$button[save]'; 
        document.forms['$form'].submit(); 
    }
    if (task=='apply')  { 
        document.forms['$form'].action = 'index.php?option=$option&d=$button[apply]'; 
        document.forms['$form'].submit(); 
    }
    if (task=='cancel') { 
        document.forms['$form'].action = 'index.php?option=$option&d=$button[cancel]'; 
        document.forms['$form'].submit(); 
    }
}
</script>
<form name="adminForm"><input name="boxchecked" type="hidden" value="true"></form>\n
EOT;
            return;
            break;

    } 
}
function not_() {/*{{{*/

}/*}}}*/
function pst_() {/*{{{*/
}/*}}}*/
function pst_var() {/*{{{*/

}/*}}}*/
function rc0() {/*{{{*/

    if (class_exists('JConfig')) {
        $jcf = new JConfig();
        define('APP_NAM', 'jos');
        define('APP_DBH', $jcf->host);
        define('APP_DBN', $jcf->db);
        define('APP_DBU', $jcf->user);
        define('APP_DBP', $jcf->password);
        define('APP_URI', JURI::base());

        if (!preg_match('/administrator/', APP_URI)) {
            echo '<script type="text/javascript" src="'.APP_URI.'includes/js/joomla.javascript.js"></script>';
        }
        JHTML::_('behavior.calendar');

    } elseif (defined('DB_HOST')) {
        define('APP_NAM', 'wps');
        define('APP_DBH', DB_HOST);
        define('APP_DBN', DB_NAME);
        define('APP_DBU', DB_USER);
        define('APP_DBP', DB_PASSWORD);
    } elseif (defined('DPL')) {
        define('APP_NAM', 'dpl');
    } else {
        define('APP_NAM', 'org');
        include('config.php');
    }/*}}}*/


    echo sty_gen();

    $link = mysql_connect(APP_DBH, APP_DBU, APP_DBP);
    if (!$link) { die('Could not connect: ' . mysql_error()); }
    mysql_select_db(APP_DBN);

    $post_self = '';
    if ($_POST) {
        $prequest_uri = preg_quote($_SERVER['REQUEST_URI'], '/');
        if (preg_match("/$prequest_uri/i", $_SERVER['HTTP_REFERER'])) {
            $post_self = 'TRUE';
        }
    }
    define('POST_SELF', $post_self);

}/*}}}*/
function rc1() {/*{{{*/
}/*}}}*/
function rnd_key($a=array()) {/*{{{*/
    $achr_pool['url'] = '01234567890abcdefghijklmnopqrstuvwxyz';
    $achr_pool['pwd'] = '!@#$%&_=+[]{};:,.?01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';

    $key_type = 'url';
    if (isset($a['key_type']) && $a['key_type']) { $key_type = $a['key_type']; }

    $chr_pool = $achr_pool[$key_type];
    if (isset($a['chr_pool']) && $a['chr_pool']) { $chr_pool = $a['chr_pool']; }

    $key_len = 8;
    if (isset($a['key_len']) && $a['key_len']) { $key_len = $a['key_len']; }

    $lenm1_key = $key_len - 1;
    $lenm1_chr_pool = strlen($chr_pool) - 1;

    $key = '';
    $atmp_mtr = array();
    for ($i=0; $i<=$lenm1_key; $i++) {
        $mtr = mt_rand(0,$lenm1_chr_pool);
        if (in_array($mtr, $atmp_mtr)) { continue; }
        $atmp_mtr[] = $mtr;
        $key .= $chr_pool[$mtr];
    } 
    return $key;
}/*}}}*/
function ses_() {/*{{{*/
}/*}}}*/
function sql_() {/*{{{*/


}/*}}}*/
function sty_gen() {/*{{{*/
$o =<<< EOT
<style>
pre {
    font: 8pt Consolas;
    background: whitesmoke;
}
#tbl_sel {
    font: 9pt Consolas;
    border-spacing: 1px;
}
#tbl_sel th {
    background: gainsboro;
}
#tbl_sel td {
    background: whitesmoke;
    padding: 0px;
}
</style>
EOT;
    return $o;
}/*}}}*/
function sys_() {/*{{{*/

}/*}}}*/
function tbl_sel($a) {/*{{{*/
    $a = cst_arr($a, 'sql'); 
    $sql = $a['sql'];
    $r = dba_sel($sql);
    $field = $r['field'];
    $data = $r['data'];

    $out  = '<table id="tbl_sel">';
    $out .= '<tr>';
    foreach ($field as $f) {
        $table_head = ucfirst($f['name']);
        $out .= "<th>$table_head</th>"; 
    } 
    $out .= '</tr>';
    foreach ($data as $d) {
        $out .= '<tr>';
        foreach ($d as $value) {
            $out .= "<td>$value</td>";
        }
        $out .= '</tr>';
    }
    $out .= '</table>';
    return $out;
}/*}}}*/
function tpl_() {/*{{{*/

}/*}}}*/
function vad_eml($value) {/*{{{*/
    if (!preg_match("/^[\ a-z0-9._-]+@[a-z0-9.-]+\.[a-z]{2,6}$/i", $value)) {
        return false;
    }
    return true;
}/*}}}*/
function vad_nem($value) {/*{{{*/
    if (!$value) {
        return false;
    }
    return true;
}/*}}}*/
function var_dmp($var) {/*{{{*/
    echo  "<pre>";
    echo var_dump($var);
    echo "</pre>";
}/*}}}*/
function wps_() {/*{{{*/

}/*}}}*/

rc0();
rc1();

?>
